(function (window, undefined) {
  let t = null
  $.fn.lazyLoad = function (attr) {
    let _this = this
    function lazyLoad() {
      if (t) clearTimeout(t)
      t = setTimeout(() => {
        let windowH = window.innerHeight || document.documentElement.clientHeight
        let scrollH = document.body.scrollTop || document.documentElement.scrollTop
        let showH = windowH + scrollH
        let imgs = _this
        for (let i = 0; i < imgs.length; i++) {
          let img_height = imgs[i].offsetHeight / imgs.length;
          if (imgs[i].offsetTop - img_height <= showH) {
            imgs[i].src = imgs[i].getAttribute(attr)
            imgs[i].style.opacity = 1;
          }
        }
      }, 100)
    }
    lazyLoad()
    window.onscroll = lazyLoad
  }
})(window)